//
//  WallDetailAnswerCell.m
//  HotWord
//
//  Created by liu huan on 13-3-19.
//
//

#import "WallDetailAnswerCell.h"
#import "ITTImageView.h"

@interface WallDetailAnswerCell ()
@property (retain, nonatomic) IBOutlet ITTImageView *userHeaderImageView;
@property (retain, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (retain, nonatomic) IBOutlet UILabel *introductionLabel;
@property (retain, nonatomic) IBOutlet UILabel *answerLabel;
@property (retain, nonatomic) IBOutlet UILabel *timeLabel;

@end

@implementation WallDetailAnswerCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setDataSourceWithQuestionAnswer:(QuestionAnswer *)answer;
{
    [_userHeaderImageView setDefaultImage:[UIImage imageNamed:@"photo_card_small.png"]];
    [_userHeaderImageView loadImage: answer.avater];
    _nickNameLabel.text = answer.nickName;
    NSTimeInterval time = [answer.timestamp doubleValue];
    if (time > 0)
    {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy年M月d日 HH:mm"];
        NSString *dateString = [dateFormatter stringFromDate:date];
        [dateFormatter release];
        _timeLabel.text = [NSString stringWithFormat:@"%@  邀请", dateString];
        
        
    }
    else
    {
        _timeLabel.text = @"邀请";
    }
    
    _introductionLabel.text = answer.introduce;
    _introductionLabel.height = [_introductionLabel.text sizeWithFont:_introductionLabel.font constrainedToSize:CGSizeMake(_introductionLabel.width, 640) lineBreakMode:UILineBreakModeCharacterWrap].height;
    
    _answerLabel.top = _introductionLabel.bottom + 6;
    
    _answerLabel.text = [NSString stringWithFormat:@"答：%@",answer.content];

    _answerLabel.height = [_answerLabel.text sizeWithFont:_answerLabel.font constrainedToSize:CGSizeMake(_answerLabel.width, 640) lineBreakMode:UILineBreakModeCharacterWrap].height;
    self.height = _answerLabel.bottom + 15;
}

- (void)dealloc
{
    [_userHeaderImageView release];
    [_nickNameLabel release];
    [_introductionLabel release];
    [_answerLabel release];
    [_timeLabel release];
    [super dealloc];
}

@end
